﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ece750project
{
    public partial class grant_staff : Form
    {
        public struct para_info_type
        {
            public int doc_id;
        }
        public para_info_type para_info;
        public grant_staff()
        {
            InitializeComponent();
        }

        private void grant_staff_Load(object sender, EventArgs e)
        {
            Fill_staff_list(para_info.doc_id);
        }
        void Fill_staff_list(int Doc_id)
        {
            DataTable DT = DB_BusinessRules.get_doc_staff(Doc_id);
            if(DT==null) return;
            staff_list.Items.Clear();
            for (int i = 0; i <= DT.Rows.Count - 1; i++)
            {
                string sn=DT.Rows[i]["staff_name"].ToString();
                bool granted = Convert.ToBoolean(DT.Rows[i]["permission_granted"]);
                int Staff_Id = Convert.ToInt32(DT.Rows[i]["person_id"]);
                ListViewItem IT = staff_list.Items.Add("");
                IT.SubItems.Add(sn);
                IT.Checked = granted;
                IT.Tag = Staff_Id;
            }

        }

        private void cancel_Click(object sender, EventArgs e)
        {
            for (int i = 0; i <= staff_list.Items.Count - 1; i++)
            {
                try
                {
                    int staff_ID = (int)staff_list.Items[i].Tag;
                    DB_BusinessRules.grant_staff(staff_ID, staff_list.Items[i].Checked);
                }

                catch (Exception ex)
                {

                }

            }
            this.Close();
        }
    }
}
